package com.yuncheng.oaApi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.constant.OaqxjOaFlowConstants;
import com.yuncheng.oaApi.entity.OaFjzykEntity;
import com.yuncheng.oaApi.entity.OaProcessBusiness;
import com.yuncheng.oaApi.entity.OaQxjsp;
import com.yuncheng.oaApi.service.IOaFjzykEntityService;
import com.yuncheng.oaApi.service.IOaProcessBusinessService;
import com.yuncheng.oaApi.service.IOaQxjspService;
import com.yuncheng.oaApi.service.OaMyInfoService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "OA-首页")
@RestController
@RequestMapping("/api/spzx-oa/oaMyInfo")
public class HomePageController {
    @Resource
    @Lazy
    private OaMyInfoService oaMyInfoService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;

    @Resource
    @Lazy
    private IOaQxjspService oaqxjspService;

    @Resource
    @Lazy
    private IOaFjzykEntityService oaFjzykService;



    @ApiOperation(value = "获取本科室-各流程任务量")
    @GetMapping(value = "getbksHjmcRwl")
    public HttpResult getbksHjmcRwl(){

        return HttpResult.ok(oaMyInfoService.getNowUserKsHjmcRwlInStat());
    }



    @ApiOperation(value = "获取本科室-各流程任务量")
    @GetMapping(value = "getbksRyrwl")
    public HttpResult getbksRyrwl(){

        return HttpResult.ok(oaMyInfoService.getNowUserKsryRwlInStat(GetCurrentUserUtils.getCurrentUserOrgId()));
    }


    @ApiOperation(value = "查询流程任务是否需要补充上传材料")
    @GetMapping(value = "bcsccl")
    public HttpResult bcsccl(){
        //获取需要补充材料的请休假流程列表
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        String userid = currentUser.getId();

        List fpidList = new ArrayList<>();
        //得到基础列表
        List<OaProcessBusiness> oaProcessBusinessesList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFuserid, userid)
                .eq(OaProcessBusiness::getFlcmb, OaFlowConstant.OA_QXJ));

        for (OaProcessBusiness oaProcessBusiness : oaProcessBusinessesList){
            String fpid = oaProcessBusiness.getFpid();
            OaQxjsp oaQxjsp = oaqxjspService.getById(fpid);
            String fts = oaQxjsp.getFts();
            //如果请假类型是需要上传材料的类型，那么就将这条记录的id保存下来
            if (oaQxjsp.getFqjlx().equals(OaqxjOaFlowConstants.QXJ_BJ) && Integer.valueOf(fts) >= 3){
                List<OaFjzykEntity> oaFjzykEntities = oaFjzykService.list(new LambdaQueryWrapper<OaFjzykEntity>()
                        .eq(OaFjzykEntity::getFoaid, fpid));
                if (CollectionUtils.isEmpty(oaFjzykEntities)){
                    fpidList.add(fpid);
                }

            }
        }
        return HttpResult.ok(fpidList);
    }






}
